<template>
  <div>
    <el-dialog :title="title" :visible.sync="form.formDialogVisible">
      <el-form :model="form">
        <el-form-item
          v-for="(v, i) in list"
          :key="i"
          :label="v.title"
          :label-width="formLabelWidth"
        >
          <el-select v-show="v.type == 'select'" v-model="form[v.field]"
          :disabled='form.id?true:false'>
            <el-option
              v-for="(m, n) in v.options"
              :key="n"
              :label="m.label"
              :value="m.label"
            >
            </el-option>
          </el-select>
          <el-input
            v-show="v.type == 'input'"
            v-model="form[v.field]"
            type="input"
          >
          </el-input>

          <el-upload
            v-show="v.type == 'frame'"
            class="avatar-uploader"
            action="http://vueshop.glbuys.com/api/user/myinfo/formdatahead?token=1ec949a15fb709370f"
            :show-file-list="false"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="form.pic" :src="form.pic" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>

          <el-input-number
            v-show="v.type == 'inputNumber'"
            v-model="form[v.field]"
            controls-position="right"
            :min="0"
          ></el-input-number>

          <el-radio-group v-model="form[v.field]" v-show="v.type == 'radio'">
            <el-radio :label="1">显示</el-radio>
            <el-radio :label="0">隐藏</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { classifyUpload, getFatherList } from "../api";
export default {
  props: ["form"],
  data() {
    return {
      formLabelWidth: "120px",
      model: 0,
      list: [],
      title: "",
    };
  },
  methods: {
    handleChange(value) {
      this.form.sort = value;
    },
    submit() {
      this.$emit("finish", this.form);
      console.log(this.form);
    },
    cancel() {
      this.$emit("finish", false);
    },
    radioChange(e) {
      this.form.is_show = !e ? 0 : 1;
    },
    beforeAvatarUpload(file) {
      let formDate = new FormData();
      formDate.append("file", file);
      formDate.append("pid", 0);
    },
  },
  created() {
    getFatherList().then((res) => {
      if (res.data.status == 200) {
        this.title = res.data.data.title;
        this.list = res.data.data.rules;
      }
    });
  },
};
</script>
<style scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
